package com.tencent.qf.common.zhiyan;

import com.alibaba.fastjson.JSONObject;
import com.tencent.qf.common.util.SpringContextUtils;
import com.tencent.zhiyan.log.sdk.ZhiyanLogTcpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;

@Slf4j
public class ZhiyanLogUtil {
    public static void sendLog(String traceId, String errMsg) {
        try {
            ApplicationContext applicationContext = SpringContextUtils.getApplicationContext();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("env", applicationContext.getEnvironment().getActiveProfiles()[0]);
            jsonObject.put("traceId", traceId);
            jsonObject.put("message", errMsg);
            ZhiyanLogTcpClient client = SpringContextUtils.getBean(ZhiyanLogTcpClient.class);
            client.log(jsonObject.toJSONString());
        } catch (Exception e) {
            log.error("上报日志错误：", e);
        }
    }
}
